package Utils;

import java.net.URL;

public class UrlUtils {
    public static String getDomainName(String url) {
        // 截取域名工具类  没有www.的是二级域名
        try {
            String domain = new URL(url).getHost();
            if (domain == null) {
                return null;
            }
            domain = domain.replaceFirst("^www.*\\.","");
            return domain;
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
